home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Extras / IFF / Old_IFF_Packages / November_1988 / Examples / PGTB / tb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-12  |  4.0 KB  |  183 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\  The Software Distillery                         */
  3. /* |. o.| || Made available to the Amiga development community             */
  4. /* | .    | || the authors:                       BBS:      */
  5. /* | o    | ||   John Mainwaring, Jim Cooper             (919)-471-6436  */
  6. /* |  . |//                                     */
  7. /* ======                                     */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9.  
  10. /* Driver program to open files for Traceback file dump */
  11.  
  12. /* version identification for copyright notice        */
  13. char *TBVers = "0.91";
  14.  
  15. #include "tb.h"
  16.  
  17. struct tbtemplate *tbdata;
  18.  
  19. int tidyproc(ret)
  20. /*  --------*/
  21. int ret;
  22. {
  23. struct udata *thisud, *nextud;
  24. struct symbol_node *thissn, *nextsn;
  25. struct line_node *thisln, *nextln;
  26. long i;
  27.  
  28. if (tbdata)
  29.    {
  30.    if(tbdata->taskname)
  31.       FreeMem(tbdata->taskname, strlen(tbdata->taskname)+1);
  32.    if(tbdata->segments)
  33.       {
  34.       for (i = 0; i < tbdata->segcount; i++)
  35.      {
  36.      thissn = tbdata->segments[i].symbols;
  37.      while (thissn)
  38.         {
  39.         nextsn = thissn->sn_next;
  40.         FreeMem((char *)thissn, thissn->sn_memsize);
  41.         thissn = nextsn;
  42.         }
  43.      thisln = tbdata->segments[i].lines;
  44.      while (thisln)
  45.         {
  46.         nextln = thisln->ln_next;
  47.         FreeMem((char *)thisln, thisln->ln_size);
  48.         thisln = nextln;
  49.         }
  50.      }
  51.       FreeMem((char *)tbdata->segments,
  52.      tbdata->segcount * sizeof(struct segment));
  53.       }
  54.    if(tbdata->filename)
  55.       FreeMem(tbdata->filename, strlen(tbdata->filename)+1);
  56.    thisud = tbdata->udhead;
  57.    while (thisud)
  58.       {
  59.       nextud = thisud->udptr;
  60.       FreeMem((char *)thisud, (thisud->udsize << 2) + 8);
  61.       thisud = nextud;
  62.       }
  63.    FreeMem((char *)tbdata, sizeof(struct tbtemplate));
  64.    }
  65.  
  66. return(ret);
  67. }
  68.  
  69. void main(argc, argv)
  70. /*   ----*/
  71. int argc;
  72. char *argv[];
  73. {
  74. char *tbfname = "Snapshot.TB", *exfname = 0;
  75. FILE *tbfile, *exfile = 0;
  76. int flags = FAILFLG; /*default - include fail address*/
  77.  
  78. if (argc >= 1)
  79.    {
  80.    if (argv[1][0] == '?')
  81.       {
  82.       fprintf(stderr,
  83. "Usage: %s [-lxsrvmu] [[TB file] executable file]\n", argv[0]);
  84.       fprintf(stderr, "  default TB file is %s\n", tbfname);
  85.       fprintf(stderr,
  86. "  -a all (life the universe and everything)    -x symbol xref -s stack\n");
  87.       fprintf(stderr,
  88. "  -r registers   -v environment -m free memory -u user data   -t trace\n");
  89.       exit(FATAL);
  90.       }
  91.    while (argv[1][0] == '-')
  92.       {
  93.       argv[1]++;
  94.       while (argv[1][0])
  95.      {
  96.      switch (argv[1][0])
  97.      {
  98.      case 'a':
  99.         flags = -1; /* sloppy way to turn everything on */
  100.         break;
  101.      case 'x':
  102.         flags = flags | SYMFLG;
  103.         break;
  104.      case 's':
  105.         flags = flags | STAKFLG;
  106.         break;
  107.      case 'r':
  108.         flags = flags | REGFLG;
  109.         break;
  110.      case 't':
  111.         flags = flags | TRACEFLG;
  112.         break;
  113.      case 'v':
  114.         flags = flags | ENVFLG;
  115.         break;
  116.      case 'm':
  117.         flags = flags | FMEMFLG;
  118.         break;
  119.      case 'u':
  120.         flags = flags | UDATFLG;
  121.         break;
  122.      }
  123.      argv[1]++;
  124.      }
  125.       argv++;
  126.       argc--;
  127.       }
  128.    if (argc == 2)
  129.       exfname = argv[1];
  130.    else if (argc > 2)
  131.       {
  132.       tbfname = argv[1];
  133.       exfname = argv[2];
  134.       }
  135.    }
  136.  
  137. if (!onexit(&tidyproc))
  138.    {
  139.    fprintf(stderr, "*** unable to set exit proc\n");
  140.    exit(FATAL);
  141.    }
  142.  
  143. if (!(tbdata = (struct tbtemplate *)
  144.            AllocMem(sizeof(struct tbtemplate), MEMF_CLEAR)))
  145.    {
  146.    fprintf(stderr, "*** unable to allocate memory\n");
  147.    exit(FATAL);
  148.    }
  149.  
  150. printf("TraceDump %s Copyright (c) 1988 The Software Distillery\n\n", TBVers);
  151.  
  152. tbfile = fopen(tbfname, "r");
  153.  
  154. if (tbfile == 0)
  155.    {
  156.    fprintf(stderr, "*** unable to open traceback file %s\n", tbfname);
  157.    exit(FATAL);
  158.    }
  159.  
  160. if (!tbread(tbfile))  exit(FATAL); /* it already printed a complaint */
  161. fclose(tbfile);
  162.  
  163. if (exfname == 0)
  164.    exfname = tbdata->taskname;
  165.  
  166. if (exfname)
  167.    {
  168.    exfile = fopen(exfname, "r");
  169.  
  170.    if (exfile == 0)
  171.       {
  172.       fprintf(stderr, "*** unable to open executable file %s\n", exfname);
  173.       /* exit(FATAL); or prompt for another try? */
  174.       }
  175.    else
  176.       if (!readsym(exfile))  exit(FATAL); /* it already printed a complaint */
  177.       fclose(exfile);
  178.    }
  179.  
  180. tbdump(flags);
  181. }
  182.  
  183.